home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / ams__l~1.zoo / src / ca_unpac.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-05  |  2.6 KB  |  104 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of the Atari Machine Specific Library,
  4. //  and is Copyright 1992 by Warwick W. Allison.
  5. //
  6. //  You are free to copy and modify these sources, provided you acknowledge
  7. //  the origin by retaining this notice, and adhere to the conditions
  8. //  described in the file COPYING.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11.  
  12. /****************************************************\
  13.  *                                                  *
  14.  *  CrackArt file decompressor.                     *
  15.  *   by Warwick Allison, May 8th 1992.              *
  16.  *                                                  *
  17.  *  Based on assembler code routine:                *
  18.  *                                                  *
  19.  *   ; Dekomprimierung von CRACK ART Bildern (CA?)  *
  20.  *   ; Copyright © Detlef Röttger 04.03.1990        *
  21.  *                                                  *
  22.  *  The full file format (in bytes) is:             *
  23.  *       'C', 'A', 1, Rez, Colours x 2, Data        *
  24.  *                                                  *
  25.  *    Data = Esc, Delta, OffsetHi, OffsetLo,        *
  26.  *           codes*, Esc, 2, 0                      *
  27.  *                                                  *
  28. \****************************************************/
  29.  
  30. #include "ca_unpac.h"
  31.  
  32. // These globals are a result of the ASM original.  Sorry.
  33. static unsigned char* location;
  34. static int CycleStart;
  35. static int Cycler;
  36. static int Size;
  37. static int Count;
  38. static int Offset;
  39.  
  40. void OutByte(char b)
  41. {
  42.     location[Cycler]=b;
  43.     Cycler+=Offset;
  44.     Count--;
  45.     if (Cycler>=Size) {
  46.         CycleStart++;
  47.         Cycler=CycleStart;
  48.     }
  49. }
  50.  
  51. unsigned char InByte(FILE* f)
  52. {
  53.     return fgetc(f);
  54. }
  55.  
  56. void LoadCrackArtData(unsigned char* To, int nel, FILE* f)
  57. {
  58.     unsigned char Esc=InByte(f);
  59.     unsigned char Delta=InByte(f);
  60.  
  61.     Offset=(InByte(f)*256+InByte(f))&0x7fff;
  62.  
  63.     location=To;
  64.     Size=nel;
  65.     Count=nel;
  66.     CycleStart=0;
  67.     Cycler=0;
  68.  
  69.     while (Count) {
  70.         unsigned int n;
  71.         unsigned char b;
  72.         unsigned char code=InByte(f);
  73.  
  74.         if (code!=Esc) {
  75.             OutByte(code);
  76.         } else {
  77.             code=InByte(f);
  78.             if (code==Esc) {
  79.                 OutByte(code);
  80.             } else if (code==0) {
  81.                 n=InByte(f)+1;
  82.                 b=InByte(f);
  83.                 while (n--) OutByte(b);
  84.             } else if (code==1) {
  85.                 n=InByte(f)*256+InByte(f)+1;
  86.                 b=InByte(f);
  87.                 while (n--) OutByte(b);
  88.             } else if (code==2) {
  89.                 n=InByte(f);
  90.                 if (n) {
  91.                     n=n*256+InByte(f)+1;
  92.                     while (n--) OutByte(Delta);
  93.                 } else {
  94.                     while (Count) OutByte(Delta);
  95.                 }
  96.             } else {
  97.                 n=code+1;
  98.                 b=InByte(f);
  99.                 while (n--) OutByte(b);
  100.             }
  101.         }
  102.     }
  103. }
  104.